using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class LookupValueMap : EntityTypeConfiguration<LookupValue>
    {
        public LookupValueMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.CODE)
                .HasMaxLength(30);

            this.Property(t => t.NAME)
                .IsRequired()
                .HasMaxLength(30);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("LookupValues");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.CODE).HasColumnName("CODE");
            this.Property(t => t.NAME).HasColumnName("NAME");
            this.Property(t => t.LookupID).HasColumnName("LookupID");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");

            // Relationships
            this.HasRequired(t => t.LookupTitle)
                .WithMany(t => t.LookupValues)
                .HasForeignKey(d => d.LookupID);

        }
    }
}
